﻿<c:MailViewBase x:Class="nyxwin.Main.View.Main.MailView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:c="clr-namespace:nyxwin.Main.View.Main"
    xmlns:lc="clr-namespace:nyxwin.Main.Controls"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:comconv="clr-namespace:nyxwin.Common.Silverlight.Converters;assembly=nyxwin.Common"
    xmlns:comctrls="clr-namespace:nyxwin.Common.Silverlight.Controls;assembly=nyxwin.Common"
    xmlns:lu="clr-namespace:nyxwin.Main.Utils"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    d:DesignHeight="480" d:DesignWidth="480">
    <c:MailViewBase.Resources>
        <Style TargetType="ListBoxItem" x:Key="ListBoxStretchStyle">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate>
                        <ContentPresenter HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,0,0,20" />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <comconv:BoolToVisibilityConverter x:Key="boolToVisibilityConverter" />
        <Style x:Key="QueryTextBlockStyle" TargetType="TextBlock">
            <Setter Property="HorizontalAlignment" Value="Right" />
            <Setter Property="VerticalAlignment" Value="Center" />
            <Setter Property="Margin" Value="12,0,0,0" />
            <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeSmall}" />
        </Style>
        <DataTemplate x:Key="mailDataTemplate">
            <Grid Margin="0,0,12,10">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="1*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition />
                </Grid.RowDefinitions>

                <StackPanel Grid.RowSpan="3" Orientation="Vertical" Margin="6,0,0,5">
                    <lc:NyxIcon Uri="{Binding NickImageUrl}" VerticalAlignment="Top" HorizontalAlignment="Center" Tap="NyxIcon_Tap">
                        <toolkit:ContextMenuService.ContextMenu>
                            <toolkit:ContextMenu>
                                <toolkit:MenuItem Header="{Binding Path=Localization.Resource.Reply}" Command="{Binding Path=ReplyCommand}" />
                                <toolkit:MenuItem Header="{Binding Path=Localization.Resource.MailsWithUser}" Command="{Binding Path=FilterByNickCommand}" />
                            </toolkit:ContextMenu>
                        </toolkit:ContextMenuService.ContextMenu>
                    </lc:NyxIcon>
                    <Ellipse Width="10" Height="10" Fill="Red" Stroke="Red" Visibility="{Binding Path=Unread, Converter={StaticResource boolToVisibilityConverter}}" />
                    <Ellipse Width="10" Height="10" Fill="#FFF1FF00" Stroke="#FFF1FF00" Visibility="{Binding Path=UnreadOther, Converter={StaticResource boolToVisibilityConverter}}" />
                </StackPanel>

                <Grid Grid.Column="1">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="1*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>

                    <StackPanel Orientation="Horizontal" Margin="12,0,0,0">
                        <comctrls:ThemeAwareIcon IconUri="{Binding Path=DirectionImage}" Width="25" Height="23" />
                        <TextBlock Text="{Binding Nick}" Style="{StaticResource PhoneTextAccentStyle}" FontWeight="Bold" FontSize="{StaticResource PhoneFontSizeMediumLarge}" VerticalAlignment="Center" Margin="6,0,12,0" />
                    </StackPanel>

                    <TextBlock Grid.Column="1" Text="{Binding DisplayTime}" Style="{StaticResource PhoneTextSubtleStyle}" FontSize="{StaticResource PhoneFontSizeSmall}" Margin="12,0,0,0" VerticalAlignment="Center" FontStyle="Italic" />

                    <StackPanel Orientation="Horizontal" Margin="0,0,0,0" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Visibility="{Binding Path=ActiveVisibility}">
                        <TextBlock Text="{Binding Path=Active.LastActivityFormat}" Style="{StaticResource PhoneTextSubtleStyle}" FontSize="{StaticResource PhoneFontSizeSmall}" />
                        <HyperlinkButton Content="{Binding Path=Active.Location}" Margin="-15,0,0,0" Padding="0,0,0,0" FontSize="{StaticResource PhoneFontSizeSmall}" Command="{Binding Path=Active.LocationCommand}" />
                    </StackPanel>
                </Grid>

                <comctrls:HtmlContentTextBox HtmlContent="{Binding Content}" Grid.Row="1" Grid.Column="1" Margin="0,5" HorizontalAlignment="Left" VerticalAlignment="Top" HorizontalContentAlignment="Left" VerticalContentAlignment="Top" />
            </Grid>
        </DataTemplate>        
    </c:MailViewBase.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="1*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <ScrollViewer>
            <StackPanel>
                <ListBox x:Name="mailsList" 
                 ItemsSource="{Binding Path=Mails}" 
                 HorizontalContentAlignment="Stretch" 
                 ItemContainerStyle="{StaticResource ListBoxStretchStyle}"
                 ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                 ScrollViewer.VerticalScrollBarVisibility="Disabled"
                 ItemTemplate="{StaticResource mailDataTemplate}"
                 />
                <Button Content="{Binding Path=Localization.Resource.MoreMails}" Command="{Binding Path=MoreCommand}"/>
            </StackPanel>
        </ScrollViewer>

        <Grid Grid.Row="1" VerticalAlignment="Bottom" Visibility="{Binding Path=QueryVisible, Converter={StaticResource boolToVisibilityConverter}}" Background="{StaticResource PhoneBackgroundBrush}">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="1*" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <TextBlock Text="{Binding Path=Localization.Resource.ByNick}"  Style="{StaticResource QueryTextBlockStyle}" />
            <TextBlock Text="{Binding Path=Localization.Resource.ByContent}" Grid.Row="1" Style="{StaticResource QueryTextBlockStyle}" />

            <TextBox Text="{Binding Path=FilterByNick, Mode=TwoWay}" Grid.Column="1" />
            <TextBox Grid.ColumnSpan="3" Text="{Binding Path=FilterByContent, Mode=TwoWay}" Grid.Column="1" Grid.Row="1" />

            <comctrls:AppBarLikeButton Grid.Column="3" Grid.Row="0" IconUri="/Icons/search.png" Command="{Binding Path=FilterCommand}" />
        </Grid>
    </Grid>
</c:MailViewBase>
